/**
 * Project Name:九色鹿
 * File Name:KuaiDiAutoNumAutoConfiguration.java
 * Package Name:com.fxp.project.express.configuration
 * Date:2021年09月14日 14:17
 * Copyright (c) 2021, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.express.configuration;

import com.fxp.project.express.config.KuaiDiAutoNumProperties;
import com.fxp.project.express.provider.AutoNumProvider;
import com.fxp.project.express.service.impl.AutoNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * ClassName:KuaiDiAutoNumAutoConfiguration<br/>
 * Function: 快递100自动识别配置<br/>
 * Date:2021年09月14日 14:17<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK 8
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "express.kuaidi.auto-num", name = "key")
@EnableConfigurationProperties({KuaiDiAutoNumProperties.class})
@Import({AutoNumProvider.class})
public class KuaiDiAutoNumAutoConfiguration {
    private final AutoNumProvider autoNumProvider;
    @Autowired
    private KuaiDiAutoNumProperties properties;

    public KuaiDiAutoNumAutoConfiguration(AutoNumProvider autoNumProvider) {
        this.autoNumProvider = autoNumProvider;
    }

    @Bean(name = "autoNumService")
    @ConditionalOnMissingBean(AutoNumService.class)
    AutoNumService autoNumServiceImpl() {
        AutoNumService.initInstance(autoNumProvider.init(properties));
        return AutoNumService.getInstance();
    }
}